package com.dirven.game.geometry;

public class Rectangle {
	
	float x1, y1,
		  x2, y2,
		  x3, y3,
		  x4, y4;
	
	/*
	 *  The corners
	 *       
	 *  [4]---l3---[3]
	 *   |          |
	 *   l4         l2
	 *   |          |
	 *  [1]---l1---[2]
	 */
	
	public Rectangle(float x, float y, float width, float height) {
		
		this.x1 = x;
		this.y1 = y;
		
		this.x2 = x + width;
		this.y2 = y;
		
		this.x3 = x + width;
		this.y3 = x + height;
		
		this.x4 = x;
		this.y4 = y + height;
	}
	
	public boolean intersectsLine(Line line) {
		
		Line l1 = new Line(x1, y1, x2, y2),
			 l2 = new Line(x2, y2, x3, y3),
			 l3 = new Line(x3, y3, x4, y4),
			 l4 = new Line(x4, y4, x1, y1);
		
		// If any of the rectangle lines intersect with the given line,
		// then the rectangle intersects the line.
		if(line.intersects(l1) || line.intersects(l2) || line.intersects(l3) || line.intersects(l4)) {
			return true;
		} else {
			return false;
		}
		
	}
	
}
